package com.tree.rpc.socket;

import com.tree.rpc.socket.service.RpcRequestHandler;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @ClassName com.tree.rpc.socket
 * Description: <类功能描述>. <br>
 * <p>
 * <使用说明>
 * </p>
 * @Author tree
 * @Date 2019-11-07 00:35
 * @Version 1.0
 */
public class BioSocketServer {

    public static ExecutorService pool = Executors.newFixedThreadPool(100);

    public  void startServer(int port) throws Exception{
        ServerSocket serverSocket = new ServerSocket(port);
        while (true){
            //阻塞，等待客户连接
            Socket socket = serverSocket.accept();
            //BIO 留的读写跟我们的线程是强绑定关系
            pool.execute(new RpcRequestHandler(socket));

        }
    }

    public static void main(String[] args) throws Exception{
        new BioSocketServer().startServer(8080);
    }
}
